import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { DeviceVO, DeviceForm, DeviceQuery, DeviceCountVO, SettingQuery } from '@/api/device/types';

/**
 * 查询用户设备列表
 * @param query
 * @returns {*}
 */
export const getUserDeviceList = (query?: DeviceQuery): AxiosPromise<DeviceVO[]> => {
  return request({
    url: '/system/deviceInfo/list',
    method: 'get',
    params: query
  });
};

/**
 * 获取用户设备详细信息
 * @param id
 */
export const getUserDeviceDetail = (id: string | number): AxiosPromise<DeviceVO> => {
  return request({
    url: '/system/deviceInfo/' + id,
    method: 'get'
  });
};

/**
 * 新增用户设备
 * @param data
 */
export const addUserDevice = (data: DeviceForm) => {
  return request({
    url: '/system/deviceInfo',
    method: 'post',
    data: data
  });
};

/**
 * 修改用户设备
 * @param data
 */
export const updateDevice = (data: DeviceForm) => {
  return request({
    url: '/system/deviceInfo',
    method: 'put',
    data: data
  });
};

/**
 * 删除测试单
 * @param id
 */
export const deleteDevice = (ids: string | number | Array<string | number>) => {
  return request({
    url: '/system/deviceInfo/' + ids,
    method: 'delete'
  });
};

/**
 * 获取设备全部 在线 离线的状态的数量
 * @param query
 * @returns {*}
 */
export const getDeviceCount = (query?: any): AxiosPromise<DeviceCountVO[]> => {
  return request({
    url: '/system/deviceInfo/count',
    method: 'get',
    params: query
  });
};

/**
 * 设置温度(统一设置L1,L2,L3,N的温度)
 */
export const settingTemperature = (query?: SettingQuery) => {
  return request({
    url: '/system/deviceInfo/setting/temperature',
    method: 'post',
    data: query
  });
};

/**
 * 设置环境 温度和湿度
 */
export const settingEnvironment = (query?: SettingQuery) => {
  return request({
    url: '/system/deviceInfo/setting/environment',
    method: 'post',
    data: query
  });
};

/**
 * 设置环境 温度和湿度
 */
export const settingElectric = (query?: SettingQuery) => {
  return request({
    url: '/system/deviceInfo/setting/electric',
    method: 'post',
    data: query
  });
};
